package com.tarena.lbs.coupon.dao.repository.impl;

import com.tarena.lbs.coupon.dao.mapper.CouponCodeMapper;
import com.tarena.lbs.coupon.dao.repository.CouponCodeRepository;
import com.tarena.lbs.coupon.pojo.po.CouponCodePO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;

/**
 * @className: CouponCodeRepositoryImpl
 * @author: Feng-hongliang
 * @date: 2025/10/11 17:54
 * @Version: 1.0
 * @description:
 */
@Slf4j
@Repository("couponCodeRepository")
public class CouponCodeRepositoryImpl implements CouponCodeRepository {
    final private CouponCodeMapper couponCodeMapper;

    public CouponCodeRepositoryImpl(CouponCodeMapper couponCodeMapper) {
        this.couponCodeMapper = couponCodeMapper;
    }

    @Override
    public int insert(CouponCodePO couponCodePO) {
        try {
            return couponCodeMapper.insert(couponCodePO);
        } catch (Exception e) {
            log.error("Failed to insert coupon code: " + e.getMessage(), e);
            throw new RuntimeException("Failed to insert coupon code: " + e.getMessage(), e);
        }
    }
}
